package com.booking.controller;

import com.booking.common.dto.ClientResp;
import com.booking.common.dto.PageReq;
import com.booking.common.dto.PageResp;
import com.booking.controller.model.req.order.OrderPageQueryReq;
import com.booking.controller.model.req.order.ServiceOrderCancelReq;
import com.booking.controller.model.req.order.ServiceOrderCommentReq;
import com.booking.controller.model.req.order.ServiceOrderCreateReq;
import com.booking.controller.model.res.ServiceOrderDetail;
import com.booking.dao.entity.ServiceOrder;
import com.booking.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Qikai.Lin
 * @date 2023/4/24
 */
@Slf4j
@RestController
@RequestMapping("/api/serviceOrder")
public class ServiceOrderController {
    @Autowired
    private OrderService orderService;
    //查看所有服务订单
    @PostMapping("/page/getAll")
    public ClientResp<PageResp<ServiceOrderDetail>> getAll(@RequestBody @Valid PageReq<OrderPageQueryReq> request) {
        return ClientResp.success(orderService.getServiceOrderPage(request));
    }
    //查看服务订单详情
    @PostMapping("/detail")
    public ClientResp<ServiceOrderDetail> detail(@RequestParam Long orderId) {
        return ClientResp.success(orderService.getServiceOrderDetail(orderId));
    }
    //创建服务订单
    @PostMapping("/create")
    public ClientResp<ServiceOrder> create(@RequestBody @Valid ServiceOrderCreateReq request) {
        return ClientResp.success(orderService.createServiceOrder(request));
    }
    //取消服务订单
    @PostMapping("/cancel")
    public ClientResp<String> cancel(@RequestBody @Valid ServiceOrderCancelReq request) {
        orderService.cancelServiceOrder(request);
        return ClientResp.success();
    }
    //终止服务订单
    @PostMapping("/shutdown")
    public ClientResp<String> shutdown(@RequestParam Long orderId) {
        orderService.shutdownServiceOrder(orderId);
        return ClientResp.success();
    }
    //评价服务订单
    @PostMapping("/comment")
    public ClientResp<String> comment(@RequestBody @Valid ServiceOrderCommentReq request) {
        orderService.commentServiceOrder(request);
        return ClientResp.success();
    }
    //支付服务订单定金
    @PostMapping("/bookingPay")
    public ClientResp<String> bookingPay(@RequestParam Long orderId) {
        orderService.payServiceOrderBooking(orderId);
        return ClientResp.success();
    }
    //支付服务订单
    @PostMapping("/pay")
    public ClientResp<String> pay(@RequestParam Long orderId) {
        orderService.payServiceOrder(orderId);
        return ClientResp.success();
    }
    //房东确认服务订单履约
    @PostMapping("/finish")
    public ClientResp<String> finish(@RequestParam Long orderId) {
        orderService.finishServiceOrder(orderId);
        return ClientResp.success();
    }
}
